# -*- coding: utf-8 -*-
from app import app
from flask import Flask, request
from flask_mail import Mail, Message
from threading import Thread

app.config['MAIL_SERVER'] = 'smtp.163.com'
app.config['MAIL_PORT'] = 25
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = '************'
app.config['MAIL_PASSWORD'] = '************'
mail = Mail(app)

msg = Message('title', sender='131****0297@163.com',
              recipients=['XXXXXXXXX@qq.com'])
msg.body = 'main message！'


def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)


def send_mail():
    print ("发送邮件成功!")
    thr = Thread(target=send_async_email, args=[app, msg])
    thr.start()
